package org.lq.his.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.apache.ibatis.annotations.Param;
import org.lq.his.pojo.Registration;
import org.lq.his.pojo.Role;
import org.lq.his.service.RegistrationService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping("/registration")
public class RegistrationController {
	@Resource
	private RegistrationService registrationService;
	
	
	public void setRegistrationService(RegistrationService registrationService) {
		this.registrationService = registrationService;
	}

	@RequestMapping("/registrationIndex")
	public String registrationIndex()throws Exception{
		return "registration/registrationIndex";
	}
	
	/**
	 * 挂号
	 * @param registration
	 * @return
	 * @throws Exception
	 */
	@RequestMapping("/registration")
	@ResponseBody
	public Map<String, String> registration(Registration registration)throws Exception{
		String result = registrationService.registration(registration);
		Map<String, String> map = new HashMap<>();
		map.put("result", result);
		return map;
	}
	//查询今天的
	@RequestMapping("/selectByToday")
	@ResponseBody
	public Map<String, Object> selectByToday(@RequestParam(defaultValue="1")Integer page,@RequestParam(defaultValue="10")Integer rows,@RequestParam(defaultValue="id")String sort,@RequestParam(defaultValue="asc")String order,Registration condition)throws Exception{
		Map<String, Object> map = new HashMap<>();
		
		int start = (page-1)*rows;
		List<Registration> list = registrationService.getByToday(start, rows, condition, sort, order);
		int total = registrationService.getCountByCondition(condition);
		map.put("rows", list);
		map.put("total", total);
		return map;
	}
	@RequestMapping("/selectByTodayWeideng")
	@ResponseBody
	public Map<String, Object> selectByTodayWeideng(@RequestParam(defaultValue="1")Integer page,@RequestParam(defaultValue="10")Integer rows,@RequestParam(defaultValue="id")String sort,@RequestParam(defaultValue="asc")String order,Registration condition)throws Exception{
		Map<String, Object> map = new HashMap<>();
		//设置为登记条件为未登记
		condition.setRegisterState(0);
		int start = (page-1)*rows;
		List<Registration> list = registrationService.getByToday(start, rows, condition, sort, order);
		int total = registrationService.getCountByCondition(condition);
		map.put("rows", list);
		map.put("total", total);
		return map;
	}
	@RequestMapping("/selectByTodayDengji")
	@ResponseBody
	public Map<String, Object> selectByTodayDengji(@RequestParam(defaultValue="1")Integer page,@RequestParam(defaultValue="10")Integer rows,@RequestParam(defaultValue="id")String sort,@RequestParam(defaultValue="asc")String order,Registration condition)throws Exception{
		Map<String, Object> map = new HashMap<>();
		//设置为登记条件为已登记
		condition.setRegisterState(0);
		
		int start = (page-1)*rows;
		List<Registration> list = registrationService.getByToday(start, rows, condition, sort, order);
		int total = registrationService.getCountByCondition(condition);
		map.put("rows", list);
		map.put("total", total);
		return map;
	}
	//查询是否有
	@RequestMapping("/selectByYseNo")
	@ResponseBody
	public Registration selectByYseNo(Registration registration)throws Exception{
		
		return registrationService.getYesNo(registration);
	}
	//换号
	@RequestMapping("/changeSigns")
	@ResponseBody
	public Map<String, String> changeSigns (Registration registration)throws Exception{
		String result = registrationService.changeSigns(registration);
		Map<String, String> map = new HashMap<>();
		map.put("result", result);
		return map;
	}
	//退号
	@RequestMapping("/hmsRepulse")
	@ResponseBody
	public Map<String, String> hmsRepulse(Integer id)throws Exception{
		
		String result = registrationService.hmsRepulse(id);
		Map<String, String> map = new HashMap<>();
		map.put("result", result);
		return map;
	}
	
	@RequestMapping("/selectById")
	@ResponseBody
	public Registration selectById(Integer id)throws Exception{
		return registrationService.getById(id);
	}
	
}
